home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / lib / dpkg / parsechangelog / debian
Encoding:
Text File  |  2012-09-17  |  4.3 KB  |  149 lines

  1. #!/usr/bin/perl
  2. #
  3. # parsechangelog/debian
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  
  18. use strict;
  19. use warnings;
  20.  
  21. use Getopt::Long qw(:config gnu_getopt auto_help);
  22. use POSIX;
  23.  
  24. use Dpkg;
  25. use Dpkg::Gettext;
  26. use Dpkg::ErrorHandling;
  27. use Dpkg::Changelog::Debian;
  28.  
  29. textdomain("dpkg-dev");
  30.  
  31. $progname = "parsechangelog/$progname";
  32.  
  33. sub version {
  34.     printf _g("Debian %s version %s.\n"), $progname, $version;
  35.  
  36.     printf _g("
  37. Copyright (C) 1996 Ian Jackson.
  38. Copyright (C) 2005,2007 Frank Lichtenheld.");
  39.     printf _g("
  40. This is free software; see the GNU General Public License version 2 or
  41. later for copying conditions. There is NO warranty.
  42. ");
  43. }
  44.  
  45. sub usage {
  46.     printf _g(
  47. "Usage: %s [<option>...] [<changelogfile>]
  48.  
  49. Options:
  50.     --help, -h                  print usage information
  51.     --version, -V               print version information
  52.     --label, -l <file>          name of the changelog file to
  53.                                 use in error messages
  54.     --file <file>               changelog file to parse, defaults
  55.                                 to '-' (standard input)
  56.     --format <outputformat>     see man page for list of available
  57.                                 output formats, defaults to 'dpkg'
  58.                                 for compatibility with dpkg-dev
  59.     --since, -s, -v <version>   include all changes later than version
  60.     --until, -u <version>       include all changes earlier than version
  61.     --from, -f <version>        include all changes equal or later
  62.                                 than version
  63.     --to, -t <version>          include all changes up to or equal
  64.                                 than version
  65.     --count, -c, -n <number>    include <number> entries from the top
  66.                                 (or the tail if <number> is lower than 0)
  67.     --offset, -o <number>       change the starting point for --count,
  68.                                 counted from the top (or the tail if
  69.                                 <number> is lower than 0)
  70.     --all                       include all changes
  71. "), $progname;
  72. }
  73.  
  74. my ( $since, $until, $from, $to, $all, $count, $offset, $file, $label );
  75. my $default_file = '-';
  76. my $format = 'dpkg';
  77. my %allowed_formats = (
  78.     dpkg => 1,
  79.     rfc822 => 1,
  80.     );
  81.  
  82. sub set_format {
  83.     my ($opt, $val) = @_;
  84.  
  85.     unless ($allowed_formats{$val}) {
  86.     usageerr(_g('output format %s not supported'), $val );
  87.     }
  88.  
  89.     $format = $val;
  90. }
  91.  
  92. GetOptions( "file=s" => \$file,
  93.         "label|l=s" => \$label,
  94.         "since|v=s" => \$since,
  95.         "until|u=s" => \$until,
  96.         "from|f=s" => \$from,
  97.         "to|t=s" => \$to,
  98.         "count|c|n=i" => \$count,
  99.         "offset|o=i" => \$offset,
  100.         "help|h" => sub{usage();exit(0)},
  101.         "version|V" => sub{version();exit(0)},
  102.         "format=s" => \&set_format,
  103.         "all|a" => \$all,
  104.         )
  105.     or do { usage(); exit(2) };
  106.  
  107. usageerr('too many arguments') if @ARGV > 1;
  108.  
  109. if (@ARGV) {
  110.     if ($file && ($file ne $ARGV[0])) {
  111.     usageerr(_g('more than one file specified (%s and %s)'),
  112.          $file, $ARGV[0] );
  113.     }
  114.     $file = $ARGV[0];
  115. }
  116.  
  117. $file ||= $default_file;
  118. $label ||= $file;
  119. unless (defined($since) or defined($until) or defined($from) or
  120.         defined($to) or defined($offset) or defined($count) or
  121.         defined($all))
  122. {
  123.     $count = 1;
  124. }
  125. my %all = $all ? ( all => $all ) : ();
  126. my $range = {
  127.     since => $since, until => $until, from => $from, to => $to,
  128.     count => $count, offset => $offset,
  129.     %all
  130. };
  131.  
  132. my $changes = Dpkg::Changelog::Debian->new(reportfile => $label, range => $range);
  133.  
  134. if ($file eq '-') {
  135.     $changes->parse(\*STDIN, _g("<standard input>"))
  136.     or error(_g('fatal error occured while parsing input'));
  137. } else {
  138.     $changes->load($file)
  139.     or error(_g('fatal error occured while parsing %s'), $file);
  140. }
  141.  
  142. eval qq{
  143.     my \$output = \$changes->$format(\$range);
  144.     print \$output if defined \$output;
  145. };
  146. if ($@) {
  147.     error("%s", $@);
  148. }
  149.